GtkFileChooserEntry: fix the computation of 'complete but not unique' and appending...
authorFederico Mena Quintero <federico@novell.com>
Fri, 23 Jan 2009 00:55:07 +0000 (00:55 +0000)
committerFederico Mena Quintero <federico@src.gnome.org>
Fri, 23 Jan 2009 00:55:07 +0000 (00:55 +0000)
2009-01-22  Federico Mena Quintero  <federico@novell.com>

Fix the computation of "complete but unique" in
GtkFileChooserEntry.  Fix the case where "/" was not appended to a
unique directory name during explicit Tab completion.

* gtk/gtkfilechooserentry.c (maybe_append_separator_to_file):
Return whether anything was appended as well as the new string
itself.
(find_common_prefix): Oops, only turn on
is_complete_not_unique_ret if we had a unique match!
(append_common_prefix): If we appended a directory separator, we
*did* expand the common prefix, so we are not in the "nothing
inserted" case.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
svn path=/trunk/; revision=22184

ChangeLog
gtk/gtkfilechooserentry.c

index 0b4071e2b29542ad9bad0fb72d4fe8f69040c602..8b148cd0370760848a3c1c28b7cb3630d93a8b73 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2009-01-22  Federico Mena Quintero  <federico@novell.com>
+
+       Fix the computation of "complete but unique" in
+       GtkFileChooserEntry.  Fix the case where "/" was not appended to a
+       unique directory name during explicit Tab completion.
+
+       * gtk/gtkfilechooserentry.c (maybe_append_separator_to_file):
+       Return whether anything was appended as well as the new string
+       itself.
+       (find_common_prefix): Oops, only turn on
+       is_complete_not_unique_ret if we had a unique match!
+       (append_common_prefix): If we appended a directory separator, we
+       *did* expand the common prefix, so we are not in the "nothing
+       inserted" case.
+
 2009-01-22  Federico Mena Quintero  <federico@novell.com>
 
        Return an error code when refreshing the entry from the user's
index 68d0624b25bb06a08509f6eacaceef17e3160184..36c405524b4a062ccdd90bb0955c236a5384f83a 100644 (file)
@@ -146,7 +146,8 @@ static gboolean completion_match_func     (GtkEntryCompletion  *comp,
                                           gpointer             data);
 static char    *maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry,
                                                GFile               *file,
-                                               gchar               *display_name);
+                                               gchar               *display_name,
+                                               gboolean            *appended);
 
 typedef enum {
   REFRESH_UP_TO_CURSOR_POSITION,
@@ -324,6 +325,7 @@ match_selected_callback (GtkEntryCompletion  *completion,
   char *display_name;
   GFile *file;
   gint pos;
+  gboolean dummy;
   
   gtk_tree_model_get (model, iter,
                      DISPLAY_NAME_COLUMN, &display_name,
@@ -338,7 +340,7 @@ match_selected_callback (GtkEntryCompletion  *completion,
       return FALSE;
     }
 
-  display_name = maybe_append_separator_to_file (chooser_entry, file, display_name);
+  display_name = maybe_append_separator_to_file (chooser_entry, file, display_name, &dummy);
 
   pos = chooser_entry->file_part_pos;
 
@@ -450,15 +452,18 @@ beep (GtkFileChooserEntry *chooser_entry)
  * return a new one if needed.  Otherwise, it will return the old one.
  * You should be safe calling
  *
- * display_name = maybe_append_separator_to_file (entry, file, display_name);
+ * display_name = maybe_append_separator_to_file (entry, file, display_name, &appended);
  * ...
  * g_free (display_name);
  */
 static char *
 maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry,
                                GFile               *file,
-                               gchar               *display_name)
+                               gchar               *display_name,
+                               gboolean            *appended)
 {
+  *appended = FALSE;
+
   if (!g_str_has_suffix (display_name, G_DIR_SEPARATOR_S) && file)
     {
       GFileInfo *info;
@@ -471,6 +476,7 @@ maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry,
            {
              gchar *tmp = display_name;
              display_name = g_strconcat (tmp, G_DIR_SEPARATOR_S, NULL);
+             *appended = TRUE;
              g_free (tmp);
            }
 
@@ -609,7 +615,7 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry,
          if (G_IS_DIR_SEPARATOR (display_name[len - 1]))
            len--;
 
-         if (strncmp (*common_prefix_ret, display_name, len) == 0)
+         if (*unique_file_ret == NULL && strncmp (*common_prefix_ret, display_name, len) == 0)
            *is_complete_not_unique_ret = TRUE;
 
          g_free (display_name);
@@ -702,21 +708,23 @@ append_common_prefix (GtkFileChooserEntry *chooser_entry,
   if (unique_file)
     {
       if (!char_after_cursor_is_directory_separator (chooser_entry))
-       common_prefix = maybe_append_separator_to_file (chooser_entry,
-                                                       unique_file,
-                                                       common_prefix);
+       {
+         gboolean appended;
+
+         common_prefix = maybe_append_separator_to_file (chooser_entry,
+                                                         unique_file,
+                                                         common_prefix,
+                                                         &appended);
+         if (appended)
+           prefix_expands_the_file_part = TRUE;
+       }
 
       g_object_unref (unique_file);
 
-      if (common_prefix)
-       {
-         if (prefix_expands_the_file_part)
-           result = COMPLETED_UNIQUE;
-         else
-           result = NOTHING_INSERTED_UNIQUE;
-       }
+      if (prefix_expands_the_file_part)
+       result = COMPLETED_UNIQUE;
       else
-       result = INVALID_INPUT;
+       result = NOTHING_INSERTED_UNIQUE;
 
       have_result = TRUE;
     }
@@ -1322,8 +1330,9 @@ populate_completion_store (GtkFileChooserEntry *chooser_entry)
        {
          gchar *display_name = g_strdup (g_file_info_get_display_name (info));
          GtkTreeIter iter;
+         gboolean dummy;
 
-          display_name = maybe_append_separator_to_file (chooser_entry, file, display_name);
+          display_name = maybe_append_separator_to_file (chooser_entry, file, display_name, &dummy);
 
          gtk_list_store_append (chooser_entry->completion_store, &iter);
          gtk_list_store_set (chooser_entry->completion_store, &iter,